package com.cy.login.config.web;


import com.cy.login.config.interceptor.ReqInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
@RequiredArgsConstructor
public class SpringWebConfig implements WebMvcConfigurer {
    @Resource
    private ReqInterceptor reqInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(reqInterceptor)
                .excludePathPatterns("/account/loginEmail")// 放行login
                .excludePathPatterns("/account/logout")// 放行login
                .excludePathPatterns("/doc.html")// 放行swagger
                .excludePathPatterns("/swagger-resources")// 放行swagger
                .excludePathPatterns("/v2/api-docs")// 放行swagger
                .excludePathPatterns("/webjars/**")// 放行内网穿透
                .addPathPatterns("/**");// 拦截所有
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("doc.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

}
